home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 301-325 / disk_313 / uucp / uucp1.lzh / src / uucico / uuxqt.c < prev    next >
C/C++ Source or Header  |  1990-01-25  |  2KB  |  128 lines

  1.  
  2. /*
  3.  *  UUXQT.C by William Loftus
  4.  *  Copyright 1988 by William Loftus.    All rights reserved.
  5.  *
  6.  *  Beta Version 0.31
  7.  *
  8.  */
  9.  
  10. #include <stdio.h>
  11. #include <string.h>
  12. #include "/version.h"
  13.  
  14. IDENT(".01");
  15.  
  16. static char names[3000];
  17. static char *pointers[300];
  18. static int file_pointer;
  19. static int error;
  20. static char* xfile;
  21. static char dfile[128];
  22. static char cmd[1024];
  23. static char ccmd[128];
  24. static char ccmd_args[128];
  25. static char buf[128];
  26. static char path[128];
  27.  
  28. #define DELIM " \t\n\r"
  29.  
  30. CXBRK()
  31. {
  32.     return(0);
  33. }
  34.  
  35. char *
  36. work_scan()
  37. {
  38.     static char name[128];
  39.     int count;
  40.  
  41.     file_pointer = 0;
  42.  
  43.     sprintf(name,"UUSPOOL:X.#?");
  44.  
  45.     count = getfnl(name,names,sizeof(names),0);
  46.  
  47.     if (count > 0) {
  48.     printf("New files have arrived.\n");
  49.  
  50.     if (strbpl(pointers,300,names) != count) {
  51.         printf("Too many execute files\n");
  52.         return (char *)NULL;
  53.     }
  54.     } else {
  55.     return (char *)NULL;
  56.     }
  57.     return (char *)1;
  58. }
  59.  
  60. char *
  61. work_next()
  62. {
  63.     return pointers[file_pointer++];
  64. }
  65.  
  66. parse(x)
  67. char *x;
  68. {
  69.     FILE *fp;
  70.     char *tmp;
  71.  
  72.     fp = fopen(x, "r");
  73.     if (fp == (char *)NULL) {
  74.     printf("Can't open file %s\n",x);
  75.     chdir(path);
  76.     return(0);
  77.     }
  78.     while (fgets(buf, sizeof buf, fp)) {
  79.     if (strncmp(buf, "F", 1) == 0)
  80.         strcpy(dfile, strtok(&buf[1],DELIM));
  81.     else if (strncmp(buf, "C", 1) == 0)
  82.         strcpy(ccmd, strtok(&buf[1],DELIM));
  83.     strcpy(ccmd_args, strtok(NULL, DELIM));
  84.     while ((tmp = (char *)strtok(NULL, DELIM)) != NULL) {
  85.          strcat(ccmd_args, " ");
  86.          strcat(ccmd_args, tmp);
  87.     }
  88.     }
  89.  
  90.     if (strncmp(ccmd, "rmail", 5) == 0) {
  91.     sprintf(cmd,"uucp:c/rmail < %s %s", dfile, ccmd_args);
  92.     } else if (strncmp(ccmd, "cunbatch", 5) == 0) {
  93.     sprintf(cmd,"uucp:c/cunbatch < %s %s", dfile, ccmd_args);
  94.     } else if (strncmp(ccmd, "rnews", 5) == 0) {
  95.     sprintf(cmd,"uucp:c/rnews < %s %s", dfile, "UseNet");
  96.     } else {
  97.     printf("Unknown command request %s  - Operation Aborted -\n", ccmd);
  98.     error = 1;
  99.     }
  100.     fclose(fp);
  101.     return(1);
  102. }
  103.  
  104.  
  105. void
  106. main()
  107. {
  108.     getcwd(path,128);
  109.     chdir("UUSPOOL:");
  110.     if (work_scan() != (char *)NULL) {
  111.     while ((xfile = work_next()) != (char *)NULL) {
  112.         LockFile(xfile);
  113.         if (parse(xfile)) {
  114.         int syserr;
  115.         if (syserr = system(cmd + 7))
  116.             syserr = system(cmd);
  117.         if (syserr == 0 && error != 1) {
  118.             remove(xfile);
  119.             remove(dfile);
  120.         }
  121.         }
  122.         UnLockFile(xfile);
  123.     }
  124.     }
  125.     chdir(path);
  126. }
  127.  
  128.